/*
 * File: Tab.c
 *
 * Code generated for Simulink model 'Tab'.
 *
 * Model version                  : 3.227
 * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
 * C/C++ source code generated on : Tue Aug 29 15:23:03 2023
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: NXP->Cortex-M4
 * Code generation objective: MISRA C:2012 guidelines
 * Validation result: Not run
 */

#include "Tab.h"
#include "Tab_private.h"
#include "RTE.h"
#include "look1_iu16lu16n16_binlcase.h"
#include "look1_iu8lu16n16tu16_binlcase.h"
#include "look2_iu16u8lu32tu16_binfcae.h"
#include "look2_iu8lu32tu16_binfcae.h"
#include "look2_iu8u16lu16n16tu1_h98F1U78.h"
#include "look2_iu8u16lu16n16tu8_XHMLsUFe.h"
#include "look2_iu8u16lu32tu16_binfcae.h"

/* Block states (default storage) */
DW_Tab_T Tab_DW;

/* Real-time model */
static RT_MODEL_Tab_T Tab_M_;
RT_MODEL_Tab_T *const Tab_M = &Tab_M_;

/* Exported data definition */

/* Definition for custom storage class: ExportToFile */
uint16_T Tab_Back_Cont_Curr = ((uint16_T)0U);/* '<S9>/Tab5' */
uint16_T Tab_Back_Pulse_Curr = ((uint16_T)0U);/* '<S8>/Tab12' */
uint16_T Tab_Dhg_Cont_Curr = ((uint16_T)0U);/* '<S5>/Tab7' */
uint16_T Tab_Dhg_Pulse_Curr = ((uint16_T)0U);/* '<S4>/Tab11' */
uint16_T Tab_enum_SOCOcv = ((uint16_T)0U);/* '<S11>/Product' */
uint16_T Tab_enum_SOCOcvAll = ((uint16_T)0U);/* '<S13>/Product' */
uint16_T Tab_mas_nmcpv = ((uint16_T)0U);/* '<S20>/Tab1' */
uint16_T Tab_pct_ChgSOC = ((uint16_T)0U);/* '<S2>/Divide' */
uint16_T Tab_pct_DsgOCV = ((uint16_T)0U);/* '<S3>/Divide' */
uint16_T Tab_qChgTabCurr = ((uint16_T)0U);/* '<S14>/Tab2' */
uint16_T Tab_sChgTabCurr = ((uint16_T)0U);/* '<S10>/Max1' */
uint16_T tabl_mv_socThreshold1 = ((uint16_T)0U);/* '<S6>/Table1' */
uint16_T tabl_mv_socThreshold2 = ((uint16_T)0U);/* '<S7>/Table1' */

/* Model step function */
void TASK_LookTab_DsgPulseCurr(void)
{
    uint8_T tmp;
    if (Rte_c_CellMaxTmp_GetVal() >= 80)
    {
        tmp = Rte_c_CellMaxTmp_GetVal();
    }
    else
    {
        tmp = Rte_c_CellMinTmp_GetVal();
    }

    Tab_Dhg_Pulse_Curr = look2_iu8u16lu16n16tu1_h98F1U78(tmp, (uint16_T)
        ((uint16_T)(soce_pct_SOC + 50U) / 100U), (&(Pccfg_DsgPluseCurr_TmpAxis[0])),
        rtCP_Tab11_bp02Data, (&(Pccfg_DsgPluseCurr_CurrTab[0])),
        rtCP_Tab11_maxIndex, 17U);
}

/* Model step function */
void TASK_LookTab_DsgContCurr(void)
{
    uint8_T tmp;
    if (Rte_c_CellMaxTmp_GetVal() >= 80)
    {
        tmp = Rte_c_CellMaxTmp_GetVal();
    }
    else
    {
        tmp = Rte_c_CellMinTmp_GetVal();
    }

    Tab_Dhg_Cont_Curr = look2_iu8u16lu16n16tu1_h98F1U78(tmp, (uint16_T)
        ((uint16_T)(soce_pct_SOC + 50U) / 100U), (&(Pccfg_DsgContCurr_TmpAxis[0])),
        rtCP_Tab7_bp02Data, (&(Pccfg_DsgContCurr_CurrTab[0])),
        rtCP_Tab7_maxIndex, 17U);
}

/* Model step function */
void TASK_LookTab_BackPulseCurr(void)
{
    uint8_T tmp;
    if (Rte_c_CellMaxTmp_GetVal() >= 80)
    {
        tmp = Rte_c_CellMaxTmp_GetVal();
    }
    else
    {
        tmp = Rte_c_CellMinTmp_GetVal();
    }

    Tab_Back_Pulse_Curr = look2_iu8u16lu16n16tu1_h98F1U78(tmp, (uint16_T)
        ((uint16_T)(soce_pct_SOC + 50U) / 100U), (&(Pccfg_BackPluseCurr_TmpAxis
        [0])), rtCP_Tab12_bp02Data, (&(Pccfg_BackPluseCurr_CurrTab[0])),
        rtCP_Tab12_maxIndex, 8U);
}

/* Model step function */
void TASK_LookTab_BackContCurr(void)
{
    uint8_T tmp;
    if (Rte_c_CellMaxTmp_GetVal() >= 80)
    {
        tmp = Rte_c_CellMaxTmp_GetVal();
    }
    else
    {
        tmp = Rte_c_CellMinTmp_GetVal();
    }

    Tab_Back_Cont_Curr = look2_iu8u16lu16n16tu1_h98F1U78(tmp, (uint16_T)
        ((uint16_T)(soce_pct_SOC + 50U) / 100U), (&(Pccfg_BackContCurr_TmpAxis[0])),
        rtCP_Tab5_bp02Data, (&(Pccfg_BackContCurr_CurrTab[0])),
        rtCP_Tab5_maxIndex, 8U);
}

/* Model step function */
void TASK_LookTab_SchgCurr(void)
{
    uint16_T u0;
    uint16_T u1;
    u0 = look2_iu16u8lu32tu16_binfcae(1U, Rte_c_CellMaxTmp_GetVal(),
        (&(Pccfg_SchgReqCurr_VolAxis[0])), (&(Pccfg_SchgReqCurr_TmpAxis[0])),
        (&(Pccfg_SchgReqCurr_CurrTab[0])), rtCP_Tab4_maxIndex, 2U);
    u1 = look2_iu16u8lu32tu16_binfcae(1U, Rte_c_CellMinTmp_GetVal(),
        (&(Pccfg_SchgReqCurr_VolAxis[0])), (&(Pccfg_SchgReqCurr_TmpAxis[0])),
        (&(Pccfg_SchgReqCurr_CurrTab[0])), rtCP_Tab1_maxIndex, 2U);
    if (u0 < u1)
    {
        Tab_sChgTabCurr = u0;
    }
    else
    {
        Tab_sChgTabCurr = u1;
    }
}

/* Model step function */
void TASK_LookTab_SOCOcv(void)
{
    uint16_T tmp;
    if ((BMS_TYPE_BATTERY == 0) || (Rte_enum_OcvAlwSts_GetVal() == 1))
    {
        tmp = 0U;
    }
    else
    {
        tmp = look1_iu8lu16n16tu16_binlcase(Rte_c_CellAvgTmp_GetVal(),
            rtCP_Tab0_bp01Data, rtCP_Tab0_tableData, 5U);
    }

    Tab_enum_SOCOcv = (uint16_T)(look2_iu8u16lu16n16tu1_h98F1U78
        (Rte_c_CellAvgTmp_GetVal(), (uint16_T)((uint32_T)
        Rte_mv_CellMinVol_GetVal() + tmp), (&(CFG_TMP_OCV_Tab[0])),
         (&(CFG_VOL_OCV_Tab[0])), (&(CFG_SOC_OCV_Tab[0])), rtCP_Tab1_maxIndex_c,
         9U) * 10U);
}

/* Model step function */
void TASK_LookTab_SOCOcvAll(void)
{
    uint16_T tmp;
    if ((BMS_TYPE_BATTERY == 0) || (Rte_enum_OcvAlwSts_GetVal() == 1))
    {
        tmp = 0U;
    }
    else
    {
        tmp = look1_iu8lu16n16tu16_binlcase(Rte_c_CellAvgTmp_GetVal(),
            rtCP_Tab0_bp01Data_d, rtCP_Tab0_tableData_n, 5U);
    }

    Tab_enum_SOCOcvAll = (uint16_T)(look2_iu8u16lu16n16tu1_h98F1U78
        (Rte_c_CellAvgTmp_GetVal(), (uint16_T)((uint32_T)
        Rte_mv_CellAvgVol_GetVal() + tmp), (&(CFG_TMP_OCV_Tab_All[0])),
         (&(CFG_VOL_OCV_Tab_All[0])), (&(CFG_SOC_OCV_Tab_All[0])),
         rtCP_Tab1_maxIndex_o, 14U) * 10U);
}

/* Model step function */
void Task_LookTab_ChgOCV(void)
{
    Tab_pct_ChgSOC = (uint16_T)(look2_iu8u16lu16n16tu1_h98F1U78
        (Rte_c_CellAvgTmp_GetVal(), Rte_mv_CellAvgVol_GetVal(),
         (&(CFG_TMP_OCV_Tab_D16C[0])), (&(CFG_VOL_OCV_Tab_D16C[0])),
         (&(CFG_SOC_OCV_Tab_D16C[0])), rtCP_Tab_D16C_maxIndex, 4U) * 10U);
}

/* Model step function */
void TASK_LookTab_NMCP(void)
{
    uint8_T tmp;
    boolean_T LogicalOperator3;
    LogicalOperator3 = ((Rte_c_CellMinTmp_GetVal() > Tab_DW.Delay2_DSTATE) ||
                        ((uint8_T)(Rte_c_CellMinTmp_GetVal() + 2U) <=
                         Tab_DW.Delay2_DSTATE));
    if (LogicalOperator3 || (vewm_enum_workingMode != Tab_DW.Delay3_DSTATE))
    {
        if (vewm_enum_workingMode == 3)
        {
            tmp = 1U;
        }
        else
        {
            tmp = 2U;
        }

        Tab_mas_nmcpv = look2_iu8lu32tu16_binfcae(tmp, Rte_c_CellMinTmp_GetVal(),
            (&(Pccfg_DCC_CURR[0])), (&(Pccfg_MIN_TEMP[0])), (&(Pccfg_NORM_CAP[0])),
            rtCP_Tab1_maxIndex_e, 3U);
    }

    Tab_DW.Delay3_DSTATE = vewm_enum_workingMode;
    if (LogicalOperator3)
    {
        Tab_DW.Delay2_DSTATE = Rte_c_CellMinTmp_GetVal();
    }
}

/* Model step function */
void Task_LookTab_DsgOCV(void)
{
    int16_T Abs;
    uint16_T VectorConcatenate1[3];
    uint16_T Tab2;
    Abs = (int16_T)((int16_T)((Rte_ma_BatCurr_GetVal() + 500U) / 1000U) - 1000);
    if (Abs > 1000)
    {
        Abs = 1000;
    }
    else
    {
        if (Abs < -1000)
        {
            Abs = -1000;
        }
    }

    if (Abs < 0)
    {
        Abs = (int16_T)-Abs;
    }

    VectorConcatenate1[0] = look2_iu8u16lu16n16tu8_XHMLsUFe
        (Rte_c_CellAvgTmp_GetVal(), Rte_mv_CellAvgVol_GetVal(),
         (&(CFG_TMP_OCV_Tab_D33C[0])), (&(CFG_VOL_OCV_Tab_D33C[0])),
         rtCP_Tab_D33C_tableData, rtCP_Tab_D33C_maxIndex, 10U);
    VectorConcatenate1[1] = look2_iu8u16lu16n16tu8_XHMLsUFe
        (Rte_c_CellAvgTmp_GetVal(), Rte_mv_CellAvgVol_GetVal(),
         (&(CFG_TMP_OCV_Tab_D5C[0])), (&(CFG_VOL_OCV_Tab_D5C[0])),
         rtCP_Tab_D33C1_tableData, rtCP_Tab_D33C1_maxIndex, 10U);
    VectorConcatenate1[2] = look2_iu8u16lu16n16tu8_XHMLsUFe
        (Rte_c_CellAvgTmp_GetVal(), Rte_mv_CellAvgVol_GetVal(),
         (&(CFG_TMP_OCV_Tab_D1C[0])), (&(CFG_VOL_OCV_Tab_D1C[0])),
         rtCP_Tab_D33C2_tableData, rtCP_Tab_D33C2_maxIndex, 10U);
    Tab2 = look1_iu16lu16n16_binlcase((uint16_T)Abs, rtCP_Tab2_bp01Data,
        VectorConcatenate1, 2U);
    Tab_pct_DsgOCV = (uint16_T)(Tab2 * 10U);
}

/* Model step function */
void Task_LookTab_SOCVoltThreshold1(void)
{
    uint8_T tmp;
    if (Rte_c_CellMaxTmp_GetVal() > 70)
    {
        tmp = Rte_c_CellMaxTmp_GetVal();
    }
    else
    {
        tmp = Rte_c_CellMinTmp_GetVal();
    }

    tabl_mv_socThreshold1 = look1_iu8lu16n16tu16_binlcase(tmp,
        (&(Pccfg_VT_Temp_Tab1[0])), (&(Pccfg_VT_TEMPVOLT_Axis1[0])), 12U);
}

/* Model step function */
void Task_LookTab_SOCVoltThreshold2(void)
{
    uint8_T tmp;
    if (Rte_c_CellMaxTmp_GetVal() > 70)
    {
        tmp = Rte_c_CellMaxTmp_GetVal();
    }
    else
    {
        tmp = Rte_c_CellMinTmp_GetVal();
    }

    tabl_mv_socThreshold2 = look1_iu8lu16n16tu16_binlcase(tmp,
        (&(Pccfg_VT_Temp_Tab2[0])), (&(Pccfg_VT_TEMPVOLT_Axis2[0])), 12U);
}

/* Model step function */
void Task_LookTab_QchgCurr(void)
{
    uint8_T tmp;
    if (Rte_c_CellMaxTmp_GetVal() >= 80)
    {
        tmp = Rte_c_CellMaxTmp_GetVal();
    }
    else
    {
        tmp = Rte_c_CellMinTmp_GetVal();
    }

    Tab_qChgTabCurr = look2_iu8u16lu32tu16_binfcae(tmp, (uint16_T)((uint16_T)
        (soce_pct_SOC + 50U) / 100U), (&(Pccfg_QchgReqCurr_TmpAxis[0])),
        (&(Pccfg_QchgReqCurr_VolAxis[0])), (&(Pccfg_QchgReqCurr_CurrTab[0])),
        rtCP_Tab2_maxIndex, 11U);
}

/* Model initialize function */
void Tab_initialize(void)
{
    /* (no initialization code required) */
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
